﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using UnityEditor;
using UnityEngine;
[CanEditMultipleObjects]
[CustomEditor(typeof(FSMSystem))]
public class FSMSystemInspector : Editor
{
    FSMSystem sys;
    SerializedProperty sp;
    bool showDirection = true;
    private void OnEnable()
    {
        sys = (FSMSystem)target;
        //通过序列化获取FSMSystem类定义的 currentState 字段,FindProperty ("字段") 
        sp = serializedObject.FindProperty("currentStateID");
    }
    public override void OnInspectorGUI()
    {
        
        serializedObject.Update();

        EditorGUILayout.BeginVertical();
        EditorGUILayout.Space();//空一行
        // EditorGUILayout.EnumMaskField()
        //在Inspector面板显示 EventType 枚举类型
        sys.currentStateID = (StateID)EditorGUILayout.EnumPopup("CurrentStateID", sys.currentStateID, GUILayout.ExpandWidth(true));
        sys.freshTime = (float)EditorGUILayout.FloatField("FreshTime", sys.freshTime, GUILayout.ExpandWidth(true));

        GUILayout.Space(10);
        showDirection=EditorGUILayout.Foldout(showDirection, "State\t\tTransition");
        if (showDirection)
        {
            foreach (var item in sys.States)
            {
                string transi = "";
                if (item.Value.Transition.Length <= 0) continue;
                    transi = item.Value.Transition[0].ID.ToString();
               EditorGUILayout.LabelField(item.Key.ToString()+" -\t"+item.Value.OutPuts[0], transi);
               
            }

        }

       // EditorGUI.LabelField(position, "");


        #region debug


        if (GUILayout.Button("Fresh"))
        {
            //打印选中的枚举值
            Debug.Log("currentStateID  :" + sys.currentStateID);
      
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }

        #endregion
        // 保存序列化数据，否则会出现设置数据丢失情况
        serializedObject.ApplyModifiedProperties();
        EditorGUILayout.EndVertical();
    }
}
